<?php namespace Admin\controller;
use Hdphp\Controller\Controller;
class NatureController extends CommonController{
	private $model;
	public function __init(){
		parent::__init();
		$this->model=new \Common\Model\Nature;
				
	}
//添加属性
	public function add(){
		$tid=Q('get.tid',0,'intval');
		View::with('tid',$tid);
		if(IS_POST){
			
			if($this->model->store()) View::success('添加成功',U('Nature/index',array('tid'=>$tid)));
			View::error($this->model->getError());
		}
		View::make();
	}
//	展示属性
	public function index(){
		$tid=Q('get.tid',0,'intval');
		View::with('tid',$tid);
		$nadata=$this->model->where("type_tid=$tid")->get();
//P($data);exit;+
//		$data=Data::tree($data,'types');
//		P($data);exit;
		View::with('nadata',$nadata);
		
		View::make();
	}
//	删除属性
	public function del(){
		$nid=Q('get.nid',0,'intval');
		$tid=Q('get.tid',0,'intval');
		View::with('tid',$tid);
//		p($tid);
		$this->model->where("nid={$nid}")->delete();
		View::success('删除成功',U('Nature/index',array('tid'=>$tid)));
	}
//	编辑属性
	public function edit(){
		$tid=Q('get.tid',0,'intval');
		View::with('tid',$tid);
		if(IS_POST){
//			p($_POST);exit;
		   	if($this->model->edit()) View::success('修改成功',U('Nature/index',array('tid'=>$tid)));
			View::error($this->model->getError());
		}
		$nid = Q('get.nid',0,'intval');
		//1.获得旧内容
		$oldData = $this->model->where("nid={$nid}")->find();
//		分配变量
		View::with('oldData',$oldData);
		
		View::make();
	}

	
	
	
	
	
}
?>